home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-02-09 | 79.5 KB | 1,973 lines |
-
- {*******************************************************}
- { }
- { Delphi Runtime Library }
- { System Utilities Unit }
- { }
- { Copyright (C) 1995,98 Borland International }
- { }
- {*******************************************************}
-
- unit SysUtils;
-
- {$H+}
-
- interface
-
- uses Windows, SysConst;
-
- const
-
- { File open modes }
-
- fmOpenRead = $0000;
- fmOpenWrite = $0001;
- fmOpenReadWrite = $0002;
- fmShareCompat = $0000;
- fmShareExclusive = $0010;
- fmShareDenyWrite = $0020;
- fmShareDenyRead = $0030;
- fmShareDenyNone = $0040;
-
- { File attribute constants }
-
- faReadOnly = $00000001;
- faHidden = $00000002;
- faSysFile = $00000004;
- faVolumeID = $00000008;
- faDirectory = $00000010;
- faArchive = $00000020;
- faAnyFile = $0000003F;
-
- { File mode magic numbers }
-
- fmClosed = $D7B0;
- fmInput = $D7B1;
- fmOutput = $D7B2;
- fmInOut = $D7B3;
-
- { Seconds and milliseconds per day }
-
- SecsPerDay = 24 * 60 * 60;
- MSecsPerDay = SecsPerDay * 1000;
-
- { Days between 1/1/0001 and 12/31/1899 }
-
- DateDelta = 693594;
-
- type
-
- { Standard Character set type }
-
- TSysCharSet = set of Char;
-
- { Type conversion records }
-
- WordRec = packed record
- Lo, Hi: Byte;
- end;
-
- LongRec = packed record
- Lo, Hi: Word;
- end;
-
- TMethod = record
- Code, Data: Pointer;
- end;
-
- { General arrays }
-
- PByteArray = ^TByteArray;
- TByteArray = array[0..32767] of Byte;
-
- PWordArray = ^TWordArray;
- TWordArray = array[0..16383] of Word;
-
- { Generic procedure pointer }
-
- TProcedure = procedure;
-
- { Generic filename type }
-
- TFileName = type string;
-
- { Search record used by FindFirst, FindNext, and FindClose }
-
- TSearchRec = record
- Time: Integer;
- Size: Integer;
- Attr: Integer;
- Name: TFileName;
- ExcludeAttr: Integer;
- FindHandle: THandle;
- FindData: TWin32FindData;
- end;
-
- { Typed-file and untyped-file record }
-
- TFileRec = record
- Handle: Integer;
- Mode: Integer;
- RecSize: Cardinal;
- Private: array[1..28] of Byte;
- UserData: array[1..32] of Byte;
- Name: array[0..259] of Char;
- end;
-
- { Text file record structure used for Text files }
-
- PTextBuf = ^TTextBuf;
- TTextBuf = array[0..127] of Char;
- TTextRec = record
- Handle: Integer;
- Mode: Integer;
- BufSize: Cardinal;
- BufPos: Cardinal;
- BufEnd: Cardinal;
- BufPtr: PChar;
- OpenFunc: Pointer;
- InOutFunc: Pointer;
- FlushFunc: Pointer;
- CloseFunc: Pointer;
- UserData: array[1..32] of Byte;
- Name: array[0..259] of Char;
- Buffer: TTextBuf;
- end;
-
- { FloatToText, FloatToTextFmt, TextToFloat, and FloatToDecimal type codes }
-
- TFloatValue = (fvExtended, fvCurrency);
-
- { FloatToText format codes }
-
- TFloatFormat = (ffGeneral, ffExponent, ffFixed, ffNumber, ffCurrency);
-
- { FloatToDecimal result record }
-
- TFloatRec = packed record
- Exponent: Smallint;
- Negative: Boolean;
- Digits: array[0..20] of Char;
- end;
-
- { Date and time record }
-
- TTimeStamp = record
- Time: Integer; { Number of milliseconds since midnight }
- Date: Integer; { One plus number of days since 1/1/0001 }
- end;
-
- { MultiByte Character Set (MBCS) byte type }
- TMbcsByteType = (mbSingleByte, mbLeadByte, mbTrailByte);
-
- { System Locale information record }
- TSysLocale = packed record
- DefaultLCID: LCID;
- PriLangID: LANGID;
- SubLangID: LANGID;
- FarEast: Boolean;
- end;
-
- { Exceptions }
-
- Exception = class(TObject)
- public
- constructor Create(const Msg: string);
- constructor CreateFmt(const Msg: string; const Args: array of const);
- constructor CreateRes(Ident: Integer; Dummy: Extended = 0);
- constructor CreateResFmt(Ident: Integer; const Args: array of const);
- constructor CreateHelp(const Msg: string; AHelpContext: Integer);
- constructor CreateFmtHelp(const Msg: string; const Args: array of const;
- AHelpContext: Integer);
- constructor CreateResHelp(Ident: Integer; AHelpContext: Integer);
- constructor CreateResFmtHelp(Ident: Integer; const Args: array of const;
- AHelpContext: Integer);
- property HelpContext: Integer;
- property Message: string;
- end;
-
- ExceptClass = class of Exception;
-
- EAbort = class(Exception);
-
- EOutOfMemory = class(Exception)
- public
- destructor Destroy; override;
- procedure FreeInstance; override;
- end;
-
- EInOutError = class(Exception)
- public
- ErrorCode: Integer;
- end;
-
- EExternal = class(Exception)
- public
- ExceptionRecord: PExceptionRecord;
- end;
-
- EExternalException = class(EExternal);
-
- EIntError = class(EExternal);
- EDivByZero = class(EIntError);
- ERangeError = class(EIntError);
- EIntOverflow = class(EIntError);
-
- EMathError = class(EExternal);
- EInvalidOp = class(EMathError);
- EZeroDivide = class(EMathError);
- EOverflow = class(EMathError);
- EUnderflow = class(EMathError);
-
- EInvalidPointer = class(Exception);
-
- EInvalidCast = class(Exception);
-
- EConvertError = class(Exception);
-
- EAccessViolation = class(EExternal);
- EPrivilege = class(EExternal);
- EStackOverflow = class(EExternal);
- EControlC = class(EExternal);
-
- EVariantError = class(Exception);
-
- EPropReadOnly = class(Exception);
- EPropWriteOnly = class(Exception);
-
- EAssertionFailed = class(Exception);
-
- EAbstractError = class(Exception);
-
- EIntfCastError = class(Exception);
-
- EInvalidContainer = class(Exception);
- EInvalidInsert = class(Exception);
-
- EPackageError = class(Exception);
-
- EWin32Error = class(Exception)
- public
- ErrorCode: DWORD;
- end;
-
- var
-
- { Empty string and null string pointer. These constants are provided for
- backwards compatibility only. }
-
- EmptyStr: string = '';
- NullStr: PString = @EmptyStr;
-
- { Win32 platform identifier. This will be one of the following values:
-
- VER_PLATFORM_WIN32s
- VER_PLATFORM_WIN32_WINDOWS
- VER_PLATFORM_WIN32_NT
-
- See WINDOWS.PAS for the numerical values. }
-
- Win32Platform: Integer = 0;
-
- { Win32 OS version information -
-
- see TOSVersionInfo.dwMajorVersion/dwMinorVersion/dwBuildNumber }
-
- Win32MajorVersion: Integer = 0;
- Win32MinorVersion: Integer = 0;
- Win32BuildNumber: Integer = 0;
-
- { Win32 OS extra version info string -
-
- see TOSVersionInfo.szCSDVersion }
-
- Win32CSDVersion: string = '';
-
- { Currency and date/time formatting options
-
- The initial values of these variables are fetched from the system registry
- using the GetLocaleInfo function in the Win32 API. The description of each
- variable specifies the LOCALE_XXXX constant used to fetch the initial
- value.
-
- CurrencyString - Defines the currency symbol used in floating-point to
- decimal conversions. The initial value is fetched from LOCALE_SCURRENCY.
-
- CurrencyFormat - Defines the currency symbol placement and separation
- used in floating-point to decimal conversions. Possible values are:
-
- 0 = '$1'
- 1 = '1$'
- 2 = '$ 1'
- 3 = '1 $'
-
- The initial value is fetched from LOCALE_ICURRENCY.
-
- NegCurrFormat - Defines the currency format for used in floating-point to
- decimal conversions of negative numbers. Possible values are:
-
- 0 = '($1)' 4 = '(1$)' 8 = '-1 $' 12 = '$ -1'
- 1 = '-$1' 5 = '-1$' 9 = '-$ 1' 13 = '1- $'
- 2 = '$-1' 6 = '1-$' 10 = '1 $-' 14 = '($ 1)'
- 3 = '$1-' 7 = '1$-' 11 = '$ 1-' 15 = '(1 $)'
-
- The initial value is fetched from LOCALE_INEGCURR.
-
- ThousandSeparator - The character used to separate thousands in numbers
- with more than three digits to the left of the decimal separator. The
- initial value is fetched from LOCALE_STHOUSAND.
-
- DecimalSeparator - The character used to separate the integer part from
- the fractional part of a number. The initial value is fetched from
- LOCALE_SDECIMAL.
-
- CurrencyDecimals - The number of digits to the right of the decimal point
- in a currency amount. The initial value is fetched from LOCALE_ICURRDIGITS.
-
- DateSeparator - The character used to separate the year, month, and day
- parts of a date value. The initial value is fetched from LOCATE_SDATE.
-
- ShortDateFormat - The format string used to convert a date value to a
- short string suitable for editing. For a complete description of date and
- time format strings, refer to the documentation for the FormatDate
- function. The short date format should only use the date separator
- character and the m, mm, d, dd, yy, and yyyy format specifiers. The
- initial value is fetched from LOCALE_SSHORTDATE.
-
- LongDateFormat - The format string used to convert a date value to a long
- string suitable for display but not for editing. For a complete description
- of date and time format strings, refer to the documentation for the
- FormatDate function. The initial value is fetched from LOCALE_SLONGDATE.
-
- TimeSeparator - The character used to separate the hour, minute, and
- second parts of a time value. The initial value is fetched from
- LOCALE_STIME.
-
- TimeAMString - The suffix string used for time values between 00:00 and
- 11:59 in 12-hour clock format. The initial value is fetched from
- LOCALE_S1159.
-
- TimePMString - The suffix string used for time values between 12:00 and
- 23:59 in 12-hour clock format. The initial value is fetched from
- LOCALE_S2359.
-
- ShortTimeFormat - The format string used to convert a time value to a
- short string with only hours and minutes. The default value is computed
- from LOCALE_ITIME and LOCALE_ITLZERO.
-
- LongTimeFormat - The format string used to convert a time value to a long
- string with hours, minutes, and seconds. The default value is computed
- from LOCALE_ITIME and LOCALE_ITLZERO.
-
- ShortMonthNames - Array of strings containing short month names. The mmm
- format specifier in a format string passed to FormatDate causes a short
- month name to be substituted. The default values are fecthed from the
- LOCALE_SABBREVMONTHNAME system locale entries.
-
- LongMonthNames - Array of strings containing long month names. The mmmm
- format specifier in a format string passed to FormatDate causes a long
- month name to be substituted. The default values are fecthed from the
- LOCALE_SMONTHNAME system locale entries.
-
- ShortDayNames - Array of strings containing short day names. The ddd
- format specifier in a format string passed to FormatDate causes a short
- day name to be substituted. The default values are fecthed from the
- LOCALE_SABBREVDAYNAME system locale entries.
-
- LongDayNames - Array of strings containing long day names. The dddd
- format specifier in a format string passed to FormatDate causes a long
- day name to be substituted. The default values are fecthed from the
- LOCALE_SDAYNAME system locale entries. }
-
- var
- CurrencyString: string;
- CurrencyFormat: Byte;
- NegCurrFormat: Byte;
- ThousandSeparator: Char;
- DecimalSeparator: Char;
- CurrencyDecimals: Byte;
- DateSeparator: Char;
- ShortDateFormat: string;
- LongDateFormat: string;
- TimeSeparator: Char;
- TimeAMString: string;
- TimePMString: string;
- ShortTimeFormat: string;
- LongTimeFormat: string;
- ShortMonthNames: array[1..12] of string;
- LongMonthNames: array[1..12] of string;
- ShortDayNames: array[1..7] of string;
- LongDayNames: array[1..7] of string;
- SysLocale: TSysLocale;
- EraNames: array[1..7] of string;
- EraYearOffsets: array[1..7] of Integer;
-
- { Memory management routines }
-
- { AllocMem allocates a block of the given size on the heap. Each byte in
- the allocated buffer is set to zero. To dispose the buffer, use the
- FreeMem standard procedure. }
-
- function AllocMem(Size: Cardinal): Pointer;
-
- { Exit procedure handling }
-
- { AddExitProc adds the given procedure to the run-time library's exit
- procedure list. When an application terminates, its exit procedures are
- executed in reverse order of definition, i.e. the last procedure passed
- to AddExitProc is the first one to get executed upon termination. }
-
- procedure AddExitProc(Proc: TProcedure);
-
- { String handling routines }
-
- { NewStr allocates a string on the heap. NewStr is provided for backwards
- compatibility only. }
-
- function NewStr(const S: string): PString;
-
- { DisposeStr disposes a string pointer that was previously allocated using
- NewStr. DisposeStr is provided for backwards compatibility only. }
-
- procedure DisposeStr(P: PString);
-
- { AssignStr assigns a new dynamically allocated string to the given string
- pointer. AssignStr is provided for backwards compatibility only. }
-
- procedure AssignStr(var P: PString; const S: string);
-
- { AppendStr appends S to the end of Dest. AppendStr is provided for
- backwards compatibility only. Use "Dest := Dest + S" instead. }
-
- procedure AppendStr(var Dest: string; const S: string);
-
- { UpperCase converts all ASCII characters in the given string to upper case.
- The conversion affects only 7-bit ASCII characters between 'a' and 'z'. To
- convert 8-bit international characters, use AnsiUpperCase. }
-
- function UpperCase(const S: string): string;
-
- { LowerCase converts all ASCII characters in the given string to lower case.
- The conversion affects only 7-bit ASCII characters between 'A' and 'Z'. To
- convert 8-bit international characters, use AnsiLowerCase. }
-
- function LowerCase(const S: string): string;
-
- { CompareStr compares S1 to S2, with case-sensitivity. The return value is
- less than 0 if S1 < S2, 0 if S1 = S2, or greater than 0 if S1 > S2. The
- compare operation is based on the 8-bit ordinal value of each character
- and is not affected by the current Windows locale. }
-
- function CompareStr(const S1, S2: string): Integer;
-
- { CompareMem performs a binary compare of Length bytes of memory referenced
- by P1 to that of P2. CompareMem returns True if the memory referenced by
- P1 is identical to that of P2. }
-
- function CompareMem(P1, P2: Pointer; Length: Integer): Boolean; assembler;
-
- { CompareText compares S1 to S2, without case-sensitivity. The return value
- is the same as for CompareStr. The compare operation is based on the 8-bit
- ordinal value of each character, after converting 'a'..'z' to 'A'..'Z',
- and is not affected by the current Windows locale. }
-
- function CompareText(const S1, S2: string): Integer;
-
- { AnsiUpperCase converts all characters in the given string to upper case.
- The conversion uses the current Windows locale. }
-
- function AnsiUpperCase(const S: string): string;
-
- { AnsiLowerCase converts all characters in the given string to lower case.
- The conversion uses the current Windows locale. }
-
- function AnsiLowerCase(const S: string): string;
-
- { AnsiCompareStr compares S1 to S2, with case-sensitivity. The compare
- operation is controlled by the current Windows locale. The return value
- is the same as for CompareStr. }
-
- function AnsiCompareStr(const S1, S2: string): Integer;
-
- { AnsiCompareText compares S1 to S2, without case-sensitivity. The compare
- operation is controlled by the current Windows locale. The return value
- is the same as for CompareStr. }
-
- function AnsiCompareText(const S1, S2: string): Integer;
-
- { AnsiStrComp compares S1 to S2, with case-sensitivity. The compare
- operation is controlled by the current Windows locale. The return value
- is the same as for CompareStr. }
-
- function AnsiStrComp(S1, S2: PChar): Integer;
-
- { AnsiStrIComp compares S1 to S2, without case-sensitivity. The compare
- operation is controlled by the current Windows locale. The return value
- is the same as for CompareStr. }
-
- function AnsiStrIComp(S1, S2: PChar): Integer;
-
- { AnsiStrLComp compares S1 to S2, with case-sensitivity, up to a maximum
- length of MaxLen bytes. The compare operation is controlled by the
- current Windows locale. The return value is the same as for CompareStr. }
-
- function AnsiStrLComp(S1, S2: PChar; MaxLen: Cardinal): Integer;
-
- { AnsiStrLIComp compares S1 to S2, without case-sensitivity, up to a maximum
- length of MaxLen bytes. The compare operation is controlled by the
- current Windows locale. The return value is the same as for CompareStr. }
-
- function AnsiStrLIComp(S1, S2: PChar; MaxLen: Cardinal): Integer;
-
- { AnsiStrLower converts all characters in the given string to lower case.
- The conversion uses the current Windows locale. }
-
- function AnsiStrLower(Str: PChar): PChar;
-
- { AnsiStrUpper converts all characters in the given string to upper case.
- The conversion uses the current Windows locale. }
-
- function AnsiStrUpper(Str: PChar): PChar;
-
- { AnsiLastChar returns a pointer to the last full character in the string.
- This function supports multibyte characters }
-
- function AnsiLastChar(const S: string): PChar;
-
- { AnsiStrLastChar returns a pointer to the last full character in the string.
- This function supports multibyte characters. }
-
- function AnsiStrLastChar(P: PChar): PChar;
-
- { Trim trims leading and trailing spaces and control characters from the
- given string. }
-
- function Trim(const S: string): string;
-
- { TrimLeft trims leading spaces and control characters from the given
- string. }
-
- function TrimLeft(const S: string): string;
-
- { TrimRight trims trailing spaces and control characters from the given
- string. }
-
- function TrimRight(const S: string): string;
-
- { QuotedStr returns the given string as a quoted string. A single quote
- character is inserted at the beginning and the end of the string, and
- for each single quote character in the string, another one is added. }
-
- function QuotedStr(const S: string): string;
-
- { AnsiQuotedStr returns the given string as a quoted string, using the
- provided Quote character. A Quote character is inserted at the beginning
- and end of thestring, and each Quote character in the string is doubled.
- This function supports multibyte character strings (MBCS). }
-
- function AnsiQuotedStr(const S: string; Quote: Char): string;
-
- { AnsiExtractQuotedStr removes the Quote characters from the beginning and end
- of a quoted string, and reduces pairs of Quote characters within the quoted
- string to a single character. If the first character in Src is not the Quote
- character, the function returns an empty string. The function copies
- characters from the Src to the result string until the second solitary
- Quote character or the first null character in Src. The Src parameter is
- updated to point to the first character following the quoted string. If
- the Src string does not contain a matching end Quote character, the Src
- parameter is updated to point to the terminating null character in Src.
- This function supports multibyte character strings (MBCS). }
-
- function AnsiExtractQuotedStr(var Src: PChar; Quote: Char): string;
-
- { AdjustLineBreaks adjusts all line breaks in the given string to be true
- CR/LF sequences. The function changes any CR characters not followed by
- a LF and any LF characters not preceded by a CR into CR/LF pairs. }
-
- function AdjustLineBreaks(const S: string): string;
-
- { IsValidIdent returns true if the given string is a valid identifier. An
- identifier is defined as a character from the set ['A'..'Z', 'a'..'z', '_']
- followed by zero or more characters from the set ['A'..'Z', 'a'..'z',
- '0..'9', '_']. }
-
- function IsValidIdent(const Ident: string): Boolean;
-
- { IntToStr converts the given value to its decimal string representation. }
-
- function IntToStr(Value: Integer): string;
-
- { IntToHex converts the given value to a hexadecimal string representation
- with the minimum number of digits specified. }
-
- function IntToHex(Value: Integer; Digits: Integer): string;
-
- { StrToInt converts the given string to an integer value. If the string
- doesn't contain a valid value, an EConvertError exception is raised. }
-
- function StrToInt(const S: string): Integer;
-
- { StrToIntDef converts the given string to an integer value. If the string
- doesn't contain a valid value, the value given by Default is returned. }
-
- function StrToIntDef(const S: string; Default: Integer): Integer;
-
- { LoadStr loads the string resource given by Ident from the application's
- executable file. If the string resource does not exist, an empty string
- is returned. }
-
- function LoadStr(Ident: Integer): string;
-
- { LoadStr loads the string resource given by Ident from the application's
- executable file, and uses it as the format string in a call to the
- Format function with the given arguments. }
-
- function FmtLoadStr(Ident: Integer; const Args: array of const): string;
-
- { File management routines }
-
- { FileOpen opens the specified file using the specified access mode. The
- access mode value is constructed by OR-ing one of the fmOpenXXXX constants
- with one of the fmShareXXXX constants. If the return value is positive,
- the function was successful and the value is the file handle of the opened
- file. A return value of -1 indicates that an error occurred. }
-
- function FileOpen(const FileName: string; Mode: Integer): Integer;
-
- { FileCreate creates a new file by the specified name. If the return value
- is positive, the function was successful and the value is the file handle
- of the new file. A return value of -1 indicates that an error occurred. }
-
- function FileCreate(const FileName: string): Integer;
-
- { FileRead reads Count bytes from the file given by Handle into the buffer
- specified by Buffer. The return value is the number of bytes actually
- read; it is less than Count if the end of the file was reached. The return
- value is -1 if an error occurred. }
-
- function FileRead(Handle: Integer; var Buffer; Count: Integer): Integer;
-
- { FileWrite writes Count bytes to the file given by Handle from the buffer
- specified by Buffer. The return value is the number of bytes actually
- written, or -1 if an error occurred. }
-
- function FileWrite(Handle: Integer; const Buffer; Count: Integer): Integer;
-
- { FileSeek changes the current position of the file given by Handle to be
- Offset bytes relative to the point given by Origin. Origin = 0 means that
- Offset is relative to the beginning of the file, Origin = 1 means that
- Offset is relative to the current position, and Origin = 2 means that
- Offset is relative to the end of the file. The return value is the new
- current position, relative to the beginning of the file, or -1 if an error
- occurred. }
-
- function FileSeek(Handle, Offset, Origin: Integer): Integer;
-
- { FileClose closes the specified file. }
-
- procedure FileClose(Handle: Integer);
-
- { FileAge returns the date-and-time stamp of the specified file. The return
- value can be converted to a TDateTime value using the FileDateToDateTime
- function. The return value is -1 if the file does not exist. }
-
- function FileAge(const FileName: string): Integer;
-
- { FileExists returns a boolean value that indicates whether the specified
- file exists. }
-
- function FileExists(const FileName: string): Boolean;
-
- { FindFirst searches the directory given by Path for the first entry that
- matches the filename given by Path and the attributes given by Attr. The
- result is returned in the search record given by SearchRec. The return
- value is zero if the function was successful. Otherwise the return value
- is a Windows error code. FindFirst is typically used in conjunction with
- FindNext and FindClose as follows:
-
- Result := FindFirst(Path, Attr, SearchRec);
- while Result = 0 do
- begin
- ProcessSearchRec(SearchRec);
- Result := FindNext(SearchRec);
- end;
- FindClose(SearchRec);
-
- where ProcessSearchRec represents user-defined code that processes the
- information in a search record. }
-
- function FindFirst(const Path: string; Attr: Integer;
- var F: TSearchRec): Integer;
-
- { FindNext returs the next entry that matches the name and attributes
- specified in a previous call to FindFirst. The search record must be one
- that was passed to FindFirst. The return value is zero if the function was
- successful. Otherwise the return value is a Windows error code. }
-
- function FindNext(var F: TSearchRec): Integer;
-
- { FindClose terminates a FindFirst/FindNext sequence. FindClose does nothing
- in the 16-bit version of Windows, but is required in the 32-bit version,
- so for maximum portability every FindFirst/FindNext sequence should end
- with a call to FindClose. }
-
- procedure FindClose(var F: TSearchRec);
-
- { FileGetDate returns the DOS date-and-time stamp of the file given by
- Handle. The return value is -1 if the handle is invalid. The
- FileDateToDateTime function can be used to convert the returned value to
- a TDateTime value. }
-
- function FileGetDate(Handle: Integer): Integer;
-
- { FileSetDate sets the DOS date-and-time stamp of the file given by Handle
- to the value given by Age. The DateTimeToFileDate function can be used to
- convert a TDateTime value to a DOS date-and-time stamp. The return value
- is zero if the function was successful. Otherwise the return value is a
- Windows error code. }
-
- function FileSetDate(Handle: Integer; Age: Integer): Integer;
-
- { FileGetAttr returns the file attributes of the file given by FileName. The
- attributes can be examined by AND-ing with the faXXXX constants defined
- above. A return value of -1 indicates that an error occurred. }
-
- function FileGetAttr(const FileName: string): Integer;
-
- { FileSetAttr sets the file attributes of the file given by FileName to the
- value given by Attr. The attribute value is formed by OR-ing the
- appropriate faXXXX constants. The return value is zero if the function was
- successful. Otherwise the return value is a Windows error code. }
-
- function FileSetAttr(const FileName: string; Attr: Integer): Integer;
-
- { DeleteFile deletes the file given by FileName. The return value is True if
- the file was successfully deleted, or False if an error occurred. }
-
- function DeleteFile(const FileName: string): Boolean;
-
- { RenameFile renames the file given by OldName to the name given by NewName.
- The return value is True if the file was successfully renamed, or False if
- an error occurred. }
-
- function RenameFile(const OldName, NewName: string): Boolean;
-
- { ChangeFileExt changes the extension of a filename. FileName specifies a
- filename with or without an extension, and Extension specifies the new
- extension for the filename. The new extension can be a an empty string or
- a period followed by up to three characters. }
-
- function ChangeFileExt(const FileName, Extension: string): string;
-
- { ExtractFilePath extracts the drive and directory parts of the given
- filename. The resulting string is the leftmost characters of FileName,
- up to and including the colon or backslash that separates the path
- information from the name and extension. The resulting string is empty
- if FileName contains no drive and directory parts. }
-
- function ExtractFilePath(const FileName: string): string;
-
- { ExtractFileDir extracts the drive and directory parts of the given
- filename. The resulting string is a directory name suitable for passing
- to SetCurrentDir, CreateDir, etc. The resulting string is empty if
- FileName contains no drive and directory parts. }
-
- function ExtractFileDir(const FileName: string): string;
-
- { ExtractFileDrive extracts the drive part of the given filename. For
- filenames with drive letters, the resulting string is '<drive>:'.
- For filenames with a UNC path, the resulting string is in the form
- '\\<servername>\<sharename>'. If the given path contains neither
- style of filename, the result is an empty string. }
-
- function ExtractFileDrive(const FileName: string): string;
-
- { ExtractFileName extracts the name and extension parts of the given
- filename. The resulting string is the leftmost characters of FileName,
- starting with the first character after the colon or backslash that
- separates the path information from the name and extension. The resulting
- string is equal to FileName if FileName contains no drive and directory
- parts. }
-
- function ExtractFileName(const FileName: string): string;
-
- { ExtractFileExt extracts the extension part of the given filename. The
- resulting string includes the period character that separates the name
- and extension parts. The resulting string is empty if the given filename
- has no extension. }
-
- function ExtractFileExt(const FileName: string): string;
-
- { ExpandFileName expands the given filename to a fully qualified filename.
- The resulting string consists of a drive letter, a colon, a root relative
- directory path, and a filename. Embedded '.' and '..' directory references
- are removed. }
-
- function ExpandFileName(const FileName: string): string;
-
- { ExpandUNCFileName expands the given filename to a fully qualified filename.
- This function is the same as ExpandFileName except that it will return the
- drive portion of the filename in the format '\\<servername>\<sharename> if
- that drive is actually a network resource instead of a local resource.
- Like ExpandFileName, embedded '.' and '..' directory references are
- removed. }
-
- function ExpandUNCFileName(const FileName: string): string;
-
- { ExtractRelativePath will return a file path name relative to the given
- BaseName. It strips the common path dirs and adds '..\' for each level
- up from the BaseName path. }
-
- function ExtractRelativePath(const BaseName, DestName: string): string;
-
- { ExtractShortPathName will convert the given filename to the short form
- by calling the GetShortPathName API. Will return an empty string if
- the file or directory specified does not exist }
-
- function ExtractShortPathName(const FileName: string): string;
-
- { FileSearch searches for the file given by Name in the list of directories
- given by DirList. The directory paths in DirList must be separated by
- semicolons. The search always starts with the current directory of the
- current drive. The returned value is a concatenation of one of the
- directory paths and the filename, or an empty string if the file could not
- be located. }
-
- function FileSearch(const Name, DirList: string): string;
-
- { DiskFree returns the number of free bytes on the specified drive number,
- where 0 = Current, 1 = A, 2 = B, etc. DiskFree returns -1 if the drive
- number is invalid. }
-
- function DiskFree(Drive: Byte): Integer;
-
- { DiskSize returns the size in bytes of the specified drive number, where
- 0 = Current, 1 = A, 2 = B, etc. DiskSize returns -1 if the drive number
- is invalid. }
-
- function DiskSize(Drive: Byte): Integer;
-
- { FileDateToDateTime converts a DOS date-and-time value to a TDateTime
- value. The FileAge, FileGetDate, and FileSetDate routines operate on DOS
- date-and-time values, and the Time field of a TSearchRec used by the
- FindFirst and FindNext functions contains a DOS date-and-time value. }
-
- function FileDateToDateTime(FileDate: Integer): TDateTime;
-
- { DateTimeToFileDate converts a TDateTime value to a DOS date-and-time
- value. The FileAge, FileGetDate, and FileSetDate routines operate on DOS
- date-and-time values, and the Time field of a TSearchRec used by the
- FindFirst and FindNext functions contains a DOS date-and-time value. }
-
- function DateTimeToFileDate(DateTime: TDateTime): Integer;
-
- { GetCurrentDir returns the current directory. }
-
- function GetCurrentDir: string;
-
- { SetCurrentDir sets the current directory. The return value is True if
- the current directory was successfully changed, or False if an error
- occurred. }
-
- function SetCurrentDir(const Dir: string): Boolean;
-
- { CreateDir creates a new directory. The return value is True if a new
- directory was successfully created, or False if an error occurred. }
-
- function CreateDir(const Dir: string): Boolean;
-
- { RemoveDir deletes an existing empty directory. The return value is
- True if the directory was successfully deleted, or False if an error
- occurred. }
-
- function RemoveDir(const Dir: string): Boolean;
-
- { PChar routines }
-
- { StrLen returns the number of characters in Str, not counting the null
- terminator. }
-
- function StrLen(Str: PChar): Cardinal;
-
- { StrEnd returns a pointer to the null character that terminates Str. }
-
- function StrEnd(Str: PChar): PChar;
-
- { StrMove copies exactly Count characters from Source to Dest and returns
- Dest. Source and Dest may overlap. }
-
- function StrMove(Dest, Source: PChar; Count: Cardinal): PChar;
-
- { StrCopy copies Source to Dest and returns Dest. }
-
- function StrCopy(Dest, Source: PChar): PChar;
-
- { StrECopy copies Source to Dest and returns StrEnd(Dest). }
-
- function StrECopy(Dest, Source: PChar): PChar;
-
- { StrLCopy copies at most MaxLen characters from Source to Dest and
- returns Dest. }
-
- function StrLCopy(Dest, Source: PChar; MaxLen: Cardinal): PChar;
-
- { StrPCopy copies the Pascal style string Source into Dest and
- returns Dest. }
-
- function StrPCopy(Dest: PChar; const Source: string): PChar;
-
- { StrPLCopy copies at most MaxLen characters from the Pascal style string
- Source into Dest and returns Dest. }
-
- function StrPLCopy(Dest: PChar; const Source: string;
- MaxLen: Cardinal): PChar;
-
- { StrCat appends a copy of Source to the end of Dest and returns Dest. }
-
- function StrCat(Dest, Source: PChar): PChar;
-
- { StrLCat appends at most MaxLen - StrLen(Dest) characters from Source to
- the end of Dest, and returns Dest. }
-
- function StrLCat(Dest, Source: PChar; MaxLen: Cardinal): PChar;
-
- { StrComp compares Str1 to Str2. The return value is less than 0 if
- Str1 < Str2, 0 if Str1 = Str2, or greater than 0 if Str1 > Str2. }
-
- function StrComp(Str1, Str2: PChar): Integer;
-
- { StrIComp compares Str1 to Str2, without case sensitivity. The return
- value is the same as StrComp. }
-
- function StrIComp(Str1, Str2: PChar): Integer;
-
- { StrLComp compares Str1 to Str2, for a maximum length of MaxLen
- characters. The return value is the same as StrComp. }
-
- function StrLComp(Str1, Str2: PChar; MaxLen: Cardinal): Integer;
-
- { StrLIComp compares Str1 to Str2, for a maximum length of MaxLen
- characters, without case sensitivity. The return value is the same
- as StrComp. }
-
- function StrLIComp(Str1, Str2: PChar; MaxLen: Cardinal): Integer;
-
- { StrScan returns a pointer to the first occurrence of Chr in Str. If Chr
- does not occur in Str, StrScan returns NIL. The null terminator is
- considered to be part of the string. }
-
- function StrScan(Str: PChar; Chr: Char): PChar;
-
- { StrRScan returns a pointer to the last occurrence of Chr in Str. If Chr
- does not occur in Str, StrRScan returns NIL. The null terminator is
- considered to be part of the string. }
-
- function StrRScan(Str: PChar; Chr: Char): PChar;
-
- { StrPos returns a pointer to the first occurrence of Str2 in Str1. If
- Str2 does not occur in Str1, StrPos returns NIL. }
-
- function StrPos(Str1, Str2: PChar): PChar;
-
- { StrUpper converts Str to upper case and returns Str. }
-
- function StrUpper(Str: PChar): PChar;
-
- { StrLower converts Str to lower case and returns Str. }
-
- function StrLower(Str: PChar): PChar;
-
- { StrPas converts Str to a Pascal style string. This function is provided
- for backwards compatibility only. To convert a null terminated string to
- a Pascal style string, use a type cast or an assignment. }
-
- function StrPas(Str: PChar): string;
-
- { StrAlloc allocates a buffer of the given size on the heap. The size of
- the allocated buffer is encoded in a four byte header that immediately
- preceeds the buffer. To dispose the buffer, use StrDispose. }
-
- function StrAlloc(Size: Cardinal): PChar;
-
- { StrBufSize returns the allocated size of the given buffer, not including
- the two byte header. }
-
- function StrBufSize(Str: PChar): Cardinal;
-
- { StrNew allocates a copy of Str on the heap. If Str is NIL, StrNew returns
- NIL and doesn't allocate any heap space. Otherwise, StrNew makes a
- duplicate of Str, obtaining space with a call to the StrAlloc function,
- and returns a pointer to the duplicated string. To dispose the string,
- use StrDispose. }
-
- function StrNew(Str: PChar): PChar;
-
- { StrDispose disposes a string that was previously allocated with StrAlloc
- or StrNew. If Str is NIL, StrDispose does nothing. }
-
- procedure StrDispose(Str: PChar);
-
- { String formatting routines }
-
- { The Format routine formats the argument list given by the Args parameter
- using the format string given by the Format parameter.
-
- Format strings contain two types of objects--plain characters and format
- specifiers. Plain characters are copied verbatim to the resulting string.
- Format specifiers fetch arguments from the argument list and apply
- formatting to them.
-
- Format specifiers have the following form:
-
- "%" [index ":"] ["-"] [width] ["." prec] type
-
- A format specifier begins with a % character. After the % come the
- following, in this order:
-
- - an optional argument index specifier, [index ":"]
- - an optional left-justification indicator, ["-"]
- - an optional width specifier, [width]
- - an optional precision specifier, ["." prec]
- - the conversion type character, type
-
- The following conversion characters are supported:
-
- d Decimal. The argument must be an integer value. The value is converted
- to a string of decimal digits. If the format string contains a precision
- specifier, it indicates that the resulting string must contain at least
- the specified number of digits; if the value has less digits, the
- resulting string is left-padded with zeros.
-
- e Scientific. The argument must be a floating-point value. The value is
- converted to a string of the form "-d.ddd...E+ddd". The resulting
- string starts with a minus sign if the number is negative, and one digit
- always precedes the decimal point. The total number of digits in the
- resulting string (including the one before the decimal point) is given
- by the precision specifer in the format string--a default precision of
- 15 is assumed if no precision specifer is present. The "E" exponent
- character in the resulting string is always followed by a plus or minus
- sign and at least three digits.
-
- f Fixed. The argument must be a floating-point value. The value is
- converted to a string of the form "-ddd.ddd...". The resulting string
- starts with a minus sign if the number is negative. The number of digits
- after the decimal point is given by the precision specifier in the
- format string--a default of 2 decimal digits is assumed if no precision
- specifier is present.
-
- g General. The argument must be a floating-point value. The value is
- converted to the shortest possible decimal string using fixed or
- scientific format. The number of significant digits in the resulting
- string is given by the precision specifier in the format string--a
- default precision of 15 is assumed if no precision specifier is present.
- Trailing zeros are removed from the resulting string, and a decimal
- point appears only if necessary. The resulting string uses fixed point
- format if the number of digits to the left of the decimal point in the
- value is less than or equal to the specified precision, and if the
- value is greater than or equal to 0.00001. Otherwise the resulting
- string uses scientific format.
-
- n Number. The argument must be a floating-point value. The value is
- converted to a string of the form "-d,ddd,ddd.ddd...". The "n" format
- corresponds to the "f" format, except that the resulting string
- contains thousand separators.
-
- m Money. The argument must be a floating-point value. The value is
- converted to a string that represents a currency amount. The conversion
- is controlled by the CurrencyString, CurrencyFormat, NegCurrFormat,
- ThousandSeparator, DecimalSeparator, and CurrencyDecimals global
- variables, all of which are initialized from the Currency Format in
- the International section of the Windows Control Panel. If the format
- string contains a precision specifier, it overrides the value given
- by the CurrencyDecimals global variable.
-
- p Pointer. The argument must be a pointer value. The value is converted
- to a string of the form "XXXX:YYYY" where XXXX and YYYY are the
- segment and offset parts of the pointer expressed as four hexadecimal
- digits.
-
- s String. The argument must be a character, a string, or a PChar value.
- The string or character is inserted in place of the format specifier.
- The precision specifier, if present in the format string, specifies the
- maximum length of the resulting string. If the argument is a string
- that is longer than this maximum, the string is truncated.
-
- x Hexadecimal. The argument must be an integer value. The value is
- converted to a string of hexadecimal digits. If the format string
- contains a precision specifier, it indicates that the resulting string
- must contain at least the specified number of digits; if the value has
- less digits, the resulting string is left-padded with zeros.
-
- Conversion characters may be specified in upper case as well as in lower
- case--both produce the same results.
-
- For all floating-point formats, the actual characters used as decimal and
- thousand separators are obtained from the DecimalSeparator and
- ThousandSeparator global variables.
-
- Index, width, and precision specifiers can be specified directly using
- decimal digit string (for example "%10d"), or indirectly using an asterisk
- charcater (for example "%*.*f"). When using an asterisk, the next argument
- in the argument list (which must be an integer value) becomes the value
- that is actually used. For example "Format('%*.*f', [8, 2, 123.456])" is
- the same as "Format('%8.2f', [123.456])".
-
- A width specifier sets the minimum field width for a conversion. If the
- resulting string is shorter than the minimum field width, it is padded
- with blanks to increase the field width. The default is to right-justify
- the result by adding blanks in front of the value, but if the format
- specifier contains a left-justification indicator (a "-" character
- preceding the width specifier), the result is left-justified by adding
- blanks after the value.
-
- An index specifier sets the current argument list index to the specified
- value. The index of the first argument in the argument list is 0. Using
- index specifiers, it is possible to format the same argument multiple
- times. For example "Format('%d %d %0:d %d', [10, 20])" produces the string
- '10 20 10 20'.
-
- The Format function can be combined with other formatting functions. For
- example
-
- S := Format('Your total was %s on %s', [
- FormatFloat('$#,##0.00;;zero', Total),
- FormatDateTime('mm/dd/yy', Date)]);
-
- which uses the FormatFloat and FormatDateTime functions to customize the
- format beyond what is possible with Format. }
-
- function Format(const Format: string; const Args: array of const): string;
-
- { FmtStr formats the argument list given by Args using the format string
- given by Format into the string variable given by Result. For further
- details, see the description of the Format function. }
-
- procedure FmtStr(var Result: string; const Format: string;
- const Args: array of const);
-
- { StrFmt formats the argument list given by Args using the format string
- given by Format into the buffer given by Buffer. It is up to the caller to
- ensure that Buffer is large enough for the resulting string. The returned
- value is Buffer. For further details, see the description of the Format
- function. }
-
- function StrFmt(Buffer, Format: PChar; const Args: array of const): PChar;
-
- { StrFmt formats the argument list given by Args using the format string
- given by Format into the buffer given by Buffer. The resulting string will
- contain no more than MaxLen characters, not including the null terminator.
- The returned value is Buffer. For further details, see the description of
- the Format function. }
-
- function StrLFmt(Buffer: PChar; MaxLen: Cardinal; Format: PChar;
- const Args: array of const): PChar;
-
- { FormatBuf formats the argument list given by Args using the format string
- given by Format and FmtLen into the buffer given by Buffer and BufLen.
- The Format parameter is a reference to a buffer containing FmtLen
- characters, and the Buffer parameter is a reference to a buffer of BufLen
- characters. The returned value is the number of characters actually stored
- in Buffer. The returned value is always less than or equal to BufLen. For
- further details, see the description of the Format function. }
-
- function FormatBuf(var Buffer; BufLen: Cardinal; const Format;
- FmtLen: Cardinal; const Args: array of const): Cardinal;
-
- { Floating point conversion routines }
-
- { FloatToStr converts the floating-point value given by Value to its string
- representation. The conversion uses general number format with 15
- significant digits. For further details, see the description of the
- FloatToStrF function. }
-
- function FloatToStr(Value: Extended): string;
-
- { CurrToStr converts the currency value given by Value to its string
- representation. The conversion uses general number format. For further
- details, see the description of the CurrToStrF function. }
-
- function CurrToStr(Value: Currency): string;
-
- { FloatToStrF converts the floating-point value given by Value to its string
- representation. The Format parameter controls the format of the resulting
- string. The Precision parameter specifies the precision of the given value.
- It should be 7 or less for values of type Single, 15 or less for values of
- type Double, and 18 or less for values of type Extended. The meaning of the
- Digits parameter depends on the particular format selected.
-
- The possible values of the Format parameter, and the meaning of each, are
- described below.
-
- ffGeneral - General number format. The value is converted to the shortest
- possible decimal string using fixed or scientific format. Trailing zeros
- are removed from the resulting string, and a decimal point appears only
- if necessary. The resulting string uses fixed point format if the number
- of digits to the left of the decimal point in the value is less than or
- equal to the specified precision, and if the value is greater than or
- equal to 0.00001. Otherwise the resulting string uses scientific format,
- and the Digits parameter specifies the minimum number of digits in the
- exponent (between 0 and 4).
-
- ffExponent - Scientific format. The value is converted to a string of the
- form "-d.ddd...E+dddd". The resulting string starts with a minus sign if
- the number is negative, and one digit always precedes the decimal point.
- The total number of digits in the resulting string (including the one
- before the decimal point) is given by the Precision parameter. The "E"
- exponent character in the resulting string is always followed by a plus
- or minus sign and up to four digits. The Digits parameter specifies the
- minimum number of digits in the exponent (between 0 and 4).
-
- ffFixed - Fixed point format. The value is converted to a string of the
- form "-ddd.ddd...". The resulting string starts with a minus sign if the
- number is negative, and at least one digit always precedes the decimal
- point. The number of digits after the decimal point is given by the Digits
- parameter--it must be between 0 and 18. If the number of digits to the
- left of the decimal point is greater than the specified precision, the
- resulting value will use scientific format.
-
- ffNumber - Number format. The value is converted to a string of the form
- "-d,ddd,ddd.ddd...". The ffNumber format corresponds to the ffFixed format,
- except that the resulting string contains thousand separators.
-
- ffCurrency - Currency format. The value is converted to a string that
- represents a currency amount. The conversion is controlled by the
- CurrencyString, CurrencyFormat, NegCurrFormat, ThousandSeparator, and
- DecimalSeparator global variables, all of which are initialized from the
- Currency Format in the International section of the Windows Control Panel.
- The number of digits after the decimal point is given by the Digits
- parameter--it must be between 0 and 18.
-
- For all formats, the actual characters used as decimal and thousand
- separators are obtained from the DecimalSeparator and ThousandSeparator
- global variables.
-
- If the given value is a NAN (not-a-number), the resulting string is 'NAN'.
- If the given value is positive infinity, the resulting string is 'INF'. If
- the given value is negative infinity, the resulting string is '-INF'. }
-
- function FloatToStrF(Value: Extended; Format: TFloatFormat;
- Precision, Digits: Integer): string;
-
- { CurrToStrF converts the currency value given by Value to its string
- representation. A call to CurrToStrF corresponds to a call to
- FloatToStrF with an implied precision of 19 digits. }
-
- function CurrToStrF(Value: Currency; Format: TFloatFormat;
- Digits: Integer): string;
-
- { FloatToText converts the given floating-point value to its decimal
- representation using the specified format, precision, and digits. The
- Value parameter must be a variable of type Extended or Currency, as
- indicated by the ValueType parameter. The resulting string of characters
- is stored in the given buffer, and the returned value is the number of
- characters stored. The resulting string is not null-terminated. For
- further details, see the description of the FloatToStrF function. }
-
- function FloatToText(Buffer: PChar; const Value; ValueType: TFloatValue;
- Format: TFloatFormat; Precision, Digits: Integer): Integer;
-
- { FormatFloat formats the floating-point value given by Value using the
- format string given by Format. The following format specifiers are
- supported in the format string:
-
- 0 Digit placeholder. If the value being formatted has a digit in the
- position where the '0' appears in the format string, then that digit
- is copied to the output string. Otherwise, a '0' is stored in that
- position in the output string.
-
- # Digit placeholder. If the value being formatted has a digit in the
- position where the '#' appears in the format string, then that digit
- is copied to the output string. Otherwise, nothing is stored in that
- position in the output string.
-
- . Decimal point. The first '.' character in the format string
- determines the location of the decimal separator in the formatted
- value; any additional '.' characters are ignored. The actual
- character used as a the decimal separator in the output string is
- determined by the DecimalSeparator global variable. The default value
- of DecimalSeparator is specified in the Number Format of the
- International section in the Windows Control Panel.
-
- , Thousand separator. If the format string contains one or more ','
- characters, the output will have thousand separators inserted between
- each group of three digits to the left of the decimal point. The
- placement and number of ',' characters in the format string does not
- affect the output, except to indicate that thousand separators are
- wanted. The actual character used as a the thousand separator in the
- output is determined by the ThousandSeparator global variable. The
- default value of ThousandSeparator is specified in the Number Format
- of the International section in the Windows Control Panel.
-
- E+ Scientific notation. If any of the strings 'E+', 'E-', 'e+', or 'e-'
- E- are contained in the format string, the number is formatted using
- e+ scientific notation. A group of up to four '0' characters can
- e- immediately follow the 'E+', 'E-', 'e+', or 'e-' to determine the
- minimum number of digits in the exponent. The 'E+' and 'e+' formats
- cause a plus sign to be output for positive exponents and a minus
- sign to be output for negative exponents. The 'E-' and 'e-' formats
- output a sign character only for negative exponents.
-
- 'xx' Characters enclosed in single or double quotes are output as-is, and
- "xx" do not affect formatting.
-
- ; Separates sections for positive, negative, and zero numbers in the
- format string.
-
- The locations of the leftmost '0' before the decimal point in the format
- string and the rightmost '0' after the decimal point in the format string
- determine the range of digits that are always present in the output string.
-
- The number being formatted is always rounded to as many decimal places as
- there are digit placeholders ('0' or '#') to the right of the decimal
- point. If the format string contains no decimal point, the value being
- formatted is rounded to the nearest whole number.
-
- If the number being formatted has more digits to the left of the decimal
- separator than there are digit placeholders to the left of the '.'
- character in the format string, the extra digits are output before the
- first digit placeholder.
-
- To allow different formats for positive, negative, and zero values, the
- format string can contain between one and three sections separated by
- semicolons.
-
- One section - The format string applies to all values.
-
- Two sections - The first section applies to positive values and zeros, and
- the second section applies to negative values.
-
- Three sections - The first section applies to positive values, the second
- applies to negative values, and the third applies to zeros.
-
- If the section for negative values or the section for zero values is empty,
- that is if there is nothing between the semicolons that delimit the
- section, the section for positive values is used instead.
-
- If the section for positive values is empty, or if the entire format string
- is empty, the value is formatted using general floating-point formatting
- with 15 significant digits, corresponding to a call to FloatToStrF with
- the ffGeneral format. General floating-point formatting is also used if
- the value has more than 18 digits to the left of the decimal point and
- the format string does not specify scientific notation.
-
- The table below shows some sample formats and the results produced when
- the formats are applied to different values:
-
- Format string 1234 -1234 0.5 0
- -----------------------------------------------------------------------
- 1234 -1234 0.5 0
- 0 1234 -1234 1 0
- 0.00 1234.00 -1234.00 0.50 0.00
- #.## 1234 -1234 .5
- #,##0.00 1,234.00 -1,234.00 0.50 0.00
- #,##0.00;(#,##0.00) 1,234.00 (1,234.00) 0.50 0.00
- #,##0.00;;Zero 1,234.00 -1,234.00 0.50 Zero
- 0.000E+00 1.234E+03 -1.234E+03 5.000E-01 0.000E+00
- #.###E-0 1.234E3 -1.234E3 5E-1 0E0
- ----------------------------------------------------------------------- }
-
- function FormatFloat(const Format: string; Value: Extended): string;
-
- { FormatCurr formats the currency value given by Value using the format
- string given by Format. For further details, see the description of the
- FormatFloat function. }
-
- function FormatCurr(const Format: string; Value: Currency): string;
-
- { FloatToTextFmt converts the given floating-point value to its decimal
- representation using the specified format. The Value parameter must be a
- variable of type Extended or Currency, as indicated by the ValueType
- parameter. The resulting string of characters is stored in the given
- buffer, and the returned value is the number of characters stored. The
- resulting string is not null-terminated. For further details, see the
- description of the FormatFloat function. }
-
- function FloatToTextFmt(Buffer: PChar; const Value; ValueType: TFloatValue;
- Format: PChar): Integer;
-
- { StrToFloat converts the given string to a floating-point value. The string
- must consist of an optional sign (+ or -), a string of digits with an
- optional decimal point, and an optional 'E' or 'e' followed by a signed
- integer. Leading and trailing blanks in the string are ignored. The
- DecimalSeparator global variable defines the character that must be used
- as a decimal point. Thousand separators and currency symbols are not
- allowed in the string. If the string doesn't contain a valid value, an
- EConvertError exception is raised. }
-
- function StrToFloat(const S: string): Extended;
-
- { StrToCurr converts the given string to a currency value. For further
- details, see the description of the StrToFloat function. }
-
- function StrToCurr(const S: string): Currency;
-
- { TextToFloat converts the null-terminated string given by Buffer to a
- floating-point value which is returned in the variable given by Value.
- The Value parameter must be a variable of type Extended or Currency, as
- indicated by the ValueType parameter. The return value is True if the
- conversion was successful, or False if the string is not a valid
- floating-point value. For further details, see the description of the
- StrToFloat function. }
-
- function TextToFloat(Buffer: PChar; var Value;
- ValueType: TFloatValue): Boolean;
-
- { FloatToDecimal converts a floating-point value to a decimal representation
- that is suited for further formatting. The Value parameter must be a
- variable of type Extended or Currency, as indicated by the ValueType
- parameter. For values of type Extended, the Precision parameter specifies
- the requested number of significant digits in the result--the allowed range
- is 1..18. For values of type Currency, the Precision parameter is ignored,
- and the implied precision of the conversion is 19 digits. The Decimals
- parameter specifies the requested maximum number of digits to the left of
- the decimal point in the result. Precision and Decimals together control
- how the result is rounded. To produce a result that always has a given
- number of significant digits regardless of the magnitude of the number,
- specify 9999 for the Decimals parameter. The result of the conversion is
- stored in the specified TFloatRec record as follows:
-
- Exponent - Contains the magnitude of the number, i.e. the number of
- significant digits to the right of the decimal point. The Exponent field
- is negative if the absolute value of the number is less than one. If the
- number is a NAN (not-a-number), Exponent is set to -32768. If the number
- is INF or -INF (positive or negative infinity), Exponent is set to 32767.
-
- Negative - True if the number is negative, False if the number is zero
- or positive.
-
- Digits - Contains up to 18 (for type Extended) or 19 (for type Currency)
- significant digits followed by a null terminator. The implied decimal
- point (if any) is not stored in Digits. Trailing zeros are removed, and
- if the resulting number is zero, NAN, or INF, Digits contains nothing but
- the null terminator. }
-
- procedure FloatToDecimal(var Result: TFloatRec; const Value;
- ValueType: TFloatValue; Precision, Decimals: Integer);
-
- { Date/time support routines }
-
- function DateTimeToTimeStamp(DateTime: TDateTime): TTimeStamp;
-
- function TimeStampToDateTime(const TimeStamp: TTimeStamp): TDateTime;
- function MSecsToTimeStamp(MSecs: Comp): TTimeStamp;
- function TimeStampToMSecs(const TimeStamp: TTimeStamp): Comp;
-
- { EncodeDate encodes the given year, month, and day into a TDateTime value.
- The year must be between 1 and 9999, the month must be between 1 and 12,
- and the day must be between 1 and N, where N is the number of days in the
- specified month. If the specified values are not within range, an
- EConvertError exception is raised. The resulting value is the number of
- days between 12/30/1899 and the given date. }
-
- function EncodeDate(Year, Month, Day: Word): TDateTime;
-
- { EncodeTime encodes the given hour, minute, second, and millisecond into a
- TDateTime value. The hour must be between 0 and 23, the minute must be
- between 0 and 59, the second must be between 0 and 59, and the millisecond
- must be between 0 and 999. If the specified values are not within range, an
- EConvertError exception is raised. The resulting value is a number between
- 0 (inclusive) and 1 (not inclusive) that indicates the fractional part of
- a day given by the specified time. The value 0 corresponds to midnight,
- 0.5 corresponds to noon, 0.75 corresponds to 6:00 pm, etc. }
-
- function EncodeTime(Hour, Min, Sec, MSec: Word): TDateTime;
-
- { DecodeDate decodes the integral (date) part of the given TDateTime value
- into its corresponding year, month, and day. If the given TDateTime value
- is less than or equal to zero, the year, month, and day return parameters
- are all set to zero. }
-
- procedure DecodeDate(Date: TDateTime; var Year, Month, Day: Word);
-
- { DecodeTime decodes the fractional (time) part of the given TDateTime value
- into its corresponding hour, minute, second, and millisecond. }
-
- procedure DecodeTime(Time: TDateTime; var Hour, Min, Sec, MSec: Word);
-
- { DateTimeToSystemTime converts a date and time from Delphi's TDateTime
- format into the Win32 API's TSystemTime format. }
-
- procedure DateTimeToSystemTime(DateTime: TDateTime; var SystemTime: TSystemTime);
-
- { SystemTimeToDateTime converts a date and time from the Win32 API's
- TSystemTime format into Delphi's TDateTime format. }
-
- function SystemTimeToDateTime(const SystemTime: TSystemTime): TDateTime;
-
- { DayOfWeek returns the day of the week of the given date. The result is an
- integer between 1 and 7, corresponding to Sunday through Saturday. }
-
- function DayOfWeek(Date: TDateTime): Integer;
-
- { Date returns the current date. }
-
- function Date: TDateTime;
-
- { Time returns the current time. }
-
- function Time: TDateTime;
-
- { Now returns the current date and time, corresponding to Date + Time. }
-
- function Now: TDateTime;
-
- { IncMonth returns Date shifted by the specified number of months.
- NumberOfMonths parameter can be negative, to return a date N months ago.
- If the input day of month is greater than the last day of the resulting
- month, the day is set to the last day of the resulting month.
- Input time of day is copied to the DateTime result. }
-
- function IncMonth(const Date: TDateTime; NumberOfMonths: Integer): TDateTime;
-
- { IsLeapYear determines whether the given year is a leap year. }
-
- function IsLeapYear(Year: Word): Boolean;
-
- type
- PDayTable = ^TDayTable;
- TDayTable = array[1..12] of Word;
-
- { The MonthDays array can be used to quickly find the number of
- days in a month: MonthDays[IsLeapYear(Y), M] }
-
- const
- MonthDays: array [Boolean] of TDayTable =
- ((31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31),
- (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31));
-
- { DateToStr converts the date part of the given TDateTime value to a string.
- The conversion uses the format specified by the ShortDateFormat global
- variable. }
-
- function DateToStr(Date: TDateTime): string;
-
- { TimeToStr converts the time part of the given TDateTime value to a string.
- The conversion uses the format specified by the LongTimeFormat global
- variable. }
-
- function TimeToStr(Time: TDateTime): string;
-
- { DateTimeToStr converts the given date and time to a string. The resulting
- string consists of a date and time formatted using the ShortDateFormat and
- LongTimeFormat global variables. Time information is included in the
- resulting string only if the fractional part of the given date and time
- value is non-zero. }
-
- function DateTimeToStr(DateTime: TDateTime): string;
-
- { StrToDate converts the given string to a date value. The string must
- consist of two or three numbers, separated by the character defined by
- the DateSeparator global variable. The order for month, day, and year is
- determined by the ShortDateFormat global variable--possible combinations
- are m/d/y, d/m/y, and y/m/d. If the string contains only two numbers, it
- is interpreted as a date (m/d or d/m) in the current year. Year values
- between 0 and 99 are assumed to be in the current century. If the given
- string does not contain a valid date, an EConvertError exception is
- raised. }
-
- function StrToDate(const S: string): TDateTime;
-
- { StrToTime converts the given string to a time value. The string must
- consist of two or three numbers, separated by the character defined by
- the TimeSeparator global variable, optionally followed by an AM or PM
- indicator. The numbers represent hour, minute, and (optionally) second,
- in that order. If the time is followed by AM or PM, it is assumed to be
- in 12-hour clock format. If no AM or PM indicator is included, the time
- is assumed to be in 24-hour clock format. If the given string does not
- contain a valid time, an EConvertError exception is raised. }
-
- function StrToTime(const S: string): TDateTime;
-
- { StrToDateTime converts the given string to a date and time value. The
- string must contain a date optionally followed by a time. The date and
- time parts of the string must follow the formats described for the
- StrToDate and StrToTime functions. }
-
- function StrToDateTime(const S: string): TDateTime;
-
- { FormatDateTime formats the date-and-time value given by DateTime using the
- format given by Format. The following format specifiers are supported:
-
- c Displays the date using the format given by the ShortDateFormat
- global variable, followed by the time using the format given by
- the LongTimeFormat global variable. The time is not displayed if
- the fractional part of the DateTime value is zero.
-
- d Displays the day as a number without a leading zero (1-31).
-
- dd Displays the day as a number with a leading zero (01-31).
-
- ddd Displays the day as an abbreviation (Sun-Sat) using the strings
- given by the ShortDayNames global variable.
-
- dddd Displays the day as a full name (Sunday-Saturday) using the strings
- given by the LongDayNames global variable.
-
- ddddd Displays the date using the format given by the ShortDateFormat
- global variable.
-
- dddddd Displays the date using the format given by the LongDateFormat
- global variable.
-
- g Displays the period/era as an abbreviation (Japanese and
- Taiwanese locales only).
-
- gg Displays the period/era as a full name.
-
- e Displays the year in the current period/era as a number without
- a leading zero (Japanese, Korean and Taiwanese locales only).
-
- ee Displays the year in the current period/era as a number with
- a leading zero (Japanese, Korean and Taiwanese locales only).
-
- m Displays the month as a number without a leading zero (1-12). If
- the m specifier immediately follows an h or hh specifier, the
- minute rather than the month is displayed.
-
- mm Displays the month as a number with a leading zero (01-12). If
- the mm specifier immediately follows an h or hh specifier, the
- minute rather than the month is displayed.
-
- mmm Displays the month as an abbreviation (Jan-Dec) using the strings
- given by the ShortMonthNames global variable.
-
- mmmm Displays the month as a full name (January-December) using the
- strings given by the LongMonthNames global variable.
-
- yy Displays the year as a two-digit number (00-99).
-
- yyyy Displays the year as a four-digit number (0000-9999).
-
- h Displays the hour without a leading zero (0-23).
-
- hh Displays the hour with a leading zero (00-23).
-
- n Displays the minute without a leading zero (0-59).
-
- nn Displays the minute with a leading zero (00-59).
-
- s Displays the second without a leading zero (0-59).
-
- ss Displays the second with a leading zero (00-59).
-
- t Displays the time using the format given by the ShortTimeFormat
- global variable.
-
- tt Displays the time using the format given by the LongTimeFormat
- global variable.
-
- am/pm Uses the 12-hour clock for the preceding h or hh specifier, and
- displays 'am' for any hour before noon, and 'pm' for any hour
- after noon. The am/pm specifier can use lower, upper, or mixed
- case, and the result is displayed accordingly.
-
- a/p Uses the 12-hour clock for the preceding h or hh specifier, and
- displays 'a' for any hour before noon, and 'p' for any hour after
- noon. The a/p specifier can use lower, upper, or mixed case, and
- the result is displayed accordingly.
-
- ampm Uses the 12-hour clock for the preceding h or hh specifier, and
- displays the contents of the TimeAMString global variable for any
- hour before noon, and the contents of the TimePMString global
- variable for any hour after noon.
-
- / Displays the date separator character given by the DateSeparator
- global variable.
-
- : Displays the time separator character given by the TimeSeparator
- global variable.
-
- 'xx' Characters enclosed in single or double quotes are displayed as-is,
- "xx" and do not affect formatting.
-
- Format specifiers may be written in upper case as well as in lower case
- letters--both produce the same result.
-
- If the string given by the Format parameter is empty, the date and time
- value is formatted as if a 'c' format specifier had been given.
-
- The following example:
-
- S := FormatDateTime('"The meeting is on" dddd, mmmm d, yyyy, ' +
- '"at" hh:mm AM/PM', StrToDateTime('2/15/95 10:30am'));
-
- assigns 'The meeting is on Wednesday, February 15, 1995 at 10:30 AM' to
- the string variable S. }
-
- function FormatDateTime(const Format: string; DateTime: TDateTime): string;
-
- { DateTimeToString converts the date and time value given by DateTime using
- the format string given by Format into the string variable given by Result.
- For further details, see the description of the FormatDateTime function. }
-
- procedure DateTimeToString(var Result: string; const Format: string;
- DateTime: TDateTime);
-
- { System error messages }
-
- function SysErrorMessage(ErrorCode: Integer): string;
-
- { Initialization file support }
-
- function GetLocaleStr(Locale, LocaleType: Integer; const Default: string): string;
- function GetLocaleChar(Locale, LocaleType: Integer; Default: Char): Char;
-
- { GetFormatSettings resets all date and number format variables to their
- default values. }
-
- procedure GetFormatSettings;
-
- { Exception handling routines }
-
- function ExceptObject: TObject;
- function ExceptAddr: Pointer;
-
- function ExceptionErrorMessage(ExceptObject: TObject; ExceptAddr: Pointer;
- Buffer: PChar; Size: Integer): Integer;
-
- procedure ShowException(ExceptObject: TObject; ExceptAddr: Pointer);
-
- procedure Abort;
-
- procedure OutOfMemoryError;
-
- procedure Beep;
-
- { MBCS functions }
-
- { LeadBytes is a char set that indicates which char values are lead bytes
- in multibyte character sets (Japanese, Chinese, etc).
- This set is always empty for western locales. }
- var
- LeadBytes: set of Char = [];
-
- { ByteType indicates what kind of byte exists at the Index'th byte in S.
- Western locales always return mbSingleByte. Far East multibyte locales
- may also return mbLeadByte, indicating the byte is the first in a multibyte
- character sequence, and mbTrailByte, indicating that the byte is the second
- in a multibyte character sequence. Parameters are assumed to be valid. }
-
- function ByteType(const S: string; Index: Integer): TMbcsByteType;
-
- { StrByteType works the same as ByteType, but on null-terminated PChar strings }
-
- function StrByteType(Str: PChar; Index: Cardinal): TMbcsByteType;
-
- { ByteToCharLen returns the character length of a MBCS string, scanning the
- string for up to MaxLen bytes. In multibyte character sets, the number of
- characters in a string may be less than the number of bytes. }
-
- function ByteToCharLen(const S: string; MaxLen: Integer): Integer;
-
- { CharToByteLen returns the byte length of a MBCS string, scanning the string
- for up to MaxLen characters. }
-
- function CharToByteLen(const S: string; MaxLen: Integer): Integer;
-
- { ByteToCharIndex returns the 1-based character index of the Index'th byte in
- a MBCS string. Returns zero if Index is out of range:
- (Index <= 0) or (Index > Length(S)) }
-
- function ByteToCharIndex(const S: string; Index: Integer): Integer;
-
- { CharToByteIndex returns the 1-based byte index of the Index'th character
- in a MBCS string. Returns zero if Index or Result are out of range:
- (Index <= 0) or (Index > Length(S)) or (Result would be > Length(S)) }
-
- function CharToByteIndex(const S: string; Index: Integer): Integer;
-
- { IsPathDelimiter returns True if the character at byte S[Index]
- is '\', and it is not a MBCS lead or trail byte. }
-
- function IsPathDelimiter(const S: string; Index: Integer): Boolean;
-
- { IsDelimiter returns True if the character at byte S[Index] matches any
- character in the Delimiters string, and the character is not a MBCS lead or
- trail byte. S may contain multibyte characters; Delimiters must contain
- only single byte characters. }
-
- function IsDelimiter(const Delimiters, S: string; Index: Integer): Boolean;
-
- { LastDelimiter returns the byte index in S of the rightmost whole
- character that matches any character in Delimiters (except null (#0)).
- S may contain multibyte characters; Delimiters must contain only single
- byte non-null characters.
- Example: LastDelimiter('\.:', 'c:\filename.ext') returns 12. }
-
- function LastDelimiter(const Delimiters, S: string): Integer;
-
- { AnsiCompareFileName supports DOS file name comparison idiosyncracies
- in Far East locales (Zenkaku). In non-MBCS locales, AnsiCompareFileName
- is identical to AnsiCompareText. For general purpose file name comparisions,
- you should use this function instead of AnsiCompareText. }
-
- function AnsiCompareFileName(const S1, S2: string): Integer;
-
- { AnsiLowerCaseFileName supports lowercase conversion idiosyncracies of
- DOS file names in Far East locales (Zenkaku). In non-MBCS locales,
- AnsiLowerCaseFileName is identical to AnsiLowerCase. }
-
- function AnsiLowerCaseFileName(const S: string): string;
-
- { AnsiUpperCaseFileName supports uppercase conversion idiosyncracies of
- DOS file names in Far East locales (Zenkaku). In non-MBCS locales,
- AnsiUpperCaseFileName is identical to AnsiUpperCase. }
-
- function AnsiUpperCaseFileName(const S: string): string;
-
- { AnsiPos: Same as Pos but supports MBCS strings }
-
- function AnsiPos(const Substr, S: string): Integer;
-
- { AnsiStrPos: Same as StrPos but supports MBCS strings }
-
- function AnsiStrPos(Str, SubStr: PChar): PChar;
-
- { AnsiStrRScan: Same as StrRScan but supports MBCS strings }
-
- function AnsiStrRScan(Str: PChar; Chr: Char): PChar;
-
- { AnsiStrScan: Same as StrScan but supports MBCS strings }
-
- function AnsiStrScan(Str: PChar; Chr: Char): PChar;
-
- { StringReplace replaces occurances of <oldpattern> with <newpattern> in a
- given string. Assumes the string may contain Multibyte characters }
-
- type
- TReplaceFlags = set of (rfReplaceAll, rfIgnoreCase);
-
- function StringReplace(const S, OldPattern, NewPattern: string;
- Flags: TReplaceFlags): string;
-
- { WrapText will scan a string for BreakChars and insert the BreakStr at the
- last BreakChar position before MaxCol. Will not insert a break into an
- embedded quoted string (both ''' and '"' supported) }
-
- function WrapText(const Line, BreakStr: string; BreakChars: TSysCharSet;
- MaxCol: Integer): string;
-
- { FindCmdLineSwitch determines whether the string in the Switch parameter
- was passed as a command line argument to the application. SwitchChars
- identifies valid argument-delimiter characters (i.e., "-" and "/" are
- common delimiters). The IgnoreCase paramter controls whether a
- case-sensistive or case-insensitive search is performed. }
-
- function FindCmdLineSwitch(const Switch: string; SwitchChars: TSysCharSet;
- IgnoreCase: Boolean): Boolean;
-
- { Package support routines }
-
- { Package Info flags }
-
- const
- pfNeverBuild = $00000001;
- pfDesignOnly = $00000002;
- pfRunOnly = $00000004;
- pfModuleTypeMask = $C0000000;
- pfExeModule = $00000000;
- pfPackageModule = $40000000;
- pfLibraryModule = $80000000;
-
- { Unit info flags }
-
- const
- ufMainUnit = $01;
- ufPackageUnit = $02;
- ufWeakUnit = $04;
- ufOrgWeakUnit = $08;
- ufImplicitUnit = $10;
-
- ufWeakPackageUnit = ufPackageUnit or ufWeakUnit;
-
- { Procedure type of the callback given to GetPackageInfo. Name is the actual
- name of the package element. If IsUnit is True then Name is the name of
- a contained unit; a required package if False. Param is the value passed
- to GetPackageInfo }
-
- type
- TNameType = (ntContainsUnit, ntRequiresPackage);
-
- TPackageInfoProc = procedure (const Name: string; NameType: TNameType; Flags: Byte; Param: Pointer);
-
- { LoadPackage loads a given package DLL, checks for duplicate units and
- calls the initialization blocks of all the contained units }
-
- function LoadPackage(const Name: string): HMODULE;
-
- { UnloadPackage does the opposite of LoadPackage by calling the finalization
- blocks of all contained units, then unloading the package DLL }
-
- procedure UnloadPackage(Module: HMODULE);
-
- { GetPackageInfo accesses the given package's info table and enumerates
- all the contained units and required packages }
-
- procedure GetPackageInfo(Module: HMODULE; Param: Pointer; var Flags: Integer;
- InfoProc: TPackageInfoProc);
-
- { GetPackageDescription loads the description resource from the package
- library. If the description resource does not exist,
- an empty string is returned. }
- function GetPackageDescription(ModuleName: PChar): string;
-
- { InitializePackage Validates and initializes the given package DLL }
-
- procedure InitializePackage(Module: HMODULE);
-
- { FinalizePackage finalizes the given package DLL }
-
- procedure FinalizePackage(Module: HMODULE);
-
- { RaiseLastWin32Error calls the GetLastError API to retrieve the code for }
- { the last occuring Win32 error. If GetLastError returns an error code, }
- { RaiseLastWin32Error then raises an exception with the error code and }
- { message associated with with error. }
-
- procedure RaiseLastWin32Error;
-
- { Win32Check is used to check the return value of a Win32 API function }
- { which returns a BOOL to indicate success. If the Win32 API function }
- { returns False (indicating failure), Win32Check calls RaiseLastWin32Error }
- { to raise an exception. If the Win32 API function returns True, }
- { Win32Check returns True. }
-
- function Win32Check(RetVal: BOOL): BOOL;
-
- { Termination procedure support }
-
- type
- TTerminateProc = function: Boolean;
-
- { Call AddTerminateProc to add a terminate procedure to the system list of }
- { termination procedures. Delphi will call all of the function in the }
- { termination procedure list before an application terminates. The user- }
- { defined TermProc function should return True if the application can }
- { safely terminate or False if the application cannot safely terminate. }
- { If one of the functions in the termination procedure list returns False, }
- { the application will not terminate. }
-
- procedure AddTerminateProc(TermProc: TTerminateProc);
-
- { CallTerminateProcs is called by VCL when an application is about to }
- { terminate. It returns True only if all of the functions in the }
- { system's terminate procedure list return True. This function is }
- { intended only to be called by Delphi, and it should not be called }
- { directly. }
-
- function CallTerminateProcs: Boolean;
-
- function GDAL: Longint;
- procedure RCS;
- procedure RPR;
-
-
- { HexDisplayPrefix contains the prefix to display on hexadecimal
- values - '$' for Pascal syntax, '0x' for C++ syntax. This is
- for display only - this does not affect the string-to-integer
- conversion routines. }
- var
- HexDisplayPrefix: string = '$';
-
- implementation
-